package com.currency.controller;

import com.currency.exception.AppException;
import com.currency.pojo.WytAdvancePayment;
import com.currency.pojo.WytCurrencyCoinsFreeze;
import com.currency.request.*;
import com.currency.response.BaseResponse;
import com.currency.response.NormalResponse;
import com.currency.response.QueryCoinsListResponse;
import com.currency.service.CoinsService;
import com.currency.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/coins")
@Api(value = "AccountController", tags = {"金币交易接口"})
public class CoinsController {
    @Autowired
    private PayService payService;

    @Autowired
    private CoinsService coinsService;

    @PostMapping("/freeze")
    @ApiOperation(value = "冻结金币接口")
    public BaseResponse freeze(@RequestBody @Validated FreezeCoinsRequest request) throws Exception {
        return payService.freezeUserCoins(request);
    }

    @PostMapping("/unfreeze")
    @ApiOperation(value = "解冻金币接口  unFreezeType 的值区分返还还是转移 trans - 金币转移    back -  金币退回解冻 ")
    public BaseResponse unfreeze(@RequestBody @Validated TransUserCoinsRequest request) throws Exception {
        return payService.transUserCoins(request);
    }

    @GetMapping("/list")
    @ApiOperation(value = "金币交易流水记录查询   coinsType: yuan - 元  fen - 分")
    public QueryCoinsListResponse coinsList(String userId, String month, String coinsType) throws Exception {
        return payService.coinsList(userId, month, coinsType);
    }

    @PostMapping("/prepay")
    @ApiOperation(value = "申请结算付款")
    public BaseResponse prePay(@RequestBody PrePayRequest request) throws AppException {
        return payService.prePay(request);
    }

    @PostMapping("/query-prepay")
    @ApiOperation(value = "查询结算信息")
    public NormalResponse queryPrepay(@RequestBody QueryPrepayRequest request) throws AppException {
        return coinsService.queryPrepay(request);
    }

    @PostMapping("add-exp-prepay")
    @ApiOperation(value = "增加结算订单额外费用")
    public BaseResponse addExtFee(@RequestBody AddExtFeeRequest request) throws AppException {
        return payService.addExtFee(request);
    }

    @GetMapping("/ensure-prepay")
    @ApiOperation(value = "结算付款通过，打款给司机")
    public BaseResponse ensurePrePay(String prePayId) throws Exception {
        return payService.ensurePrePay(prePayId);
    }

    @GetMapping("/hasten-prepay")
    @ApiOperation(value = "催促审核结算付款")
    public BaseResponse hastenPrepay(String prePayId) throws AppException {
        return coinsService.hastenPrepay(prePayId);
    }

    @PostMapping("/freeze-coins-page")
    @ApiOperation(value = "查询冻结记录")
    public NormalResponse<List<WytCurrencyCoinsFreeze>> freezeCoinsPage(@RequestBody UserIdNormalRequest request) throws AppException {
        return coinsService.freezeCoinsPage(request);
    }

    @PostMapping("/query-advance-payment")
    @ApiOperation(value = "提前付款查询接口")
    public NormalResponse<List<WytAdvancePayment>> queryAdvancePayment(@RequestBody UserIdNormalRequest request) {
        return coinsService.queryAdvancePayment(request);
    }

    @PostMapping("/advance-payment")
    @ApiOperation(value = "提前付款申请接口")
    public BaseResponse advancePayment(@RequestBody AdvancePaymentRequest request) throws AppException {
        return coinsService.advancePayment(request);
    }

    @GetMapping("/ensure-advance-payment")
    @ApiOperation(value = "提前付款申请审核通过接口")
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse ensureAdvancePayment(String id) throws AppException {
        return coinsService.ensureAdvancePayment(id);
    }

    @PostMapping("/oil-card-withdrawal")
    @ApiOperation(value = "油卡线下提现申请")
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse oilCardWithdrawal(@RequestBody OilCardWithdrawalRequest request) throws Exception {
        return coinsService.oilCardWithdrawal(request);
    }

    @PostMapping("/ensure-oil-card-withdrawal")
    @ApiOperation(value = "通过油卡线下提现申请")
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse ensureOilCardWithdrawal(@RequestBody EnsureOilCardWithdrawalRequest request) throws Exception {
        return coinsService.ensureOilCardWithdrawal(request);
    }
}
